package com.treasure.mall.zbqmallmanager.controller.integral;

import com.treasure.mall.biz.dto.condition.integral.IntegralCountCondition;
import com.treasure.mall.biz.entity.integral.IntegralCountPO;
import com.treasure.mall.biz.service.core.integral.IntegralCountService;
import com.treasure.mall.zbq.common.constant.Constant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author allan
 * @version 1.0.0
 * @date 2020/8/31
 */
@Controller
@RequestMapping("/integral")
public class IntegralController {
    @Autowired
    private IntegralCountService countService;

    @GetMapping("/statistics")
    public String statistics(
            @ModelAttribute("condition") IntegralCountCondition condition,
            @RequestParam(required = false, defaultValue = "1") int pageIndex,
            Model model
    ) {
        Page<IntegralCountPO> pos = countService.findAll(pageIndex, Constant.DEFAULT_PAGE_SIZE, condition);

        model.addAttribute("pageIndex", pageIndex);
        model.addAttribute("totalRecords", pos.getTotalElements());
        model.addAttribute("totalPages", pos.getTotalPages());
        model.addAttribute("list", pos.getContent());

        return "integral/integral_statistics";
    }
}
